#include <iostream>
#include <fstream>
#include "bundle.h"
using namespace std;

int main(int argc, char* argv[])
{
  if(argc < 3)
  {
    cout << "格式错误" << endl;
    exit(-1);
  }

  string ifilename = argv[1];
  string ofilename = argv[2];

  ifstream ifs;
  ifs.open(ifilename, std::ios::binary);
  ifs.seekg(0, std::ios::end);
  size_t len = ifs.tellg();
  ifs.seekg(0, std::ios::beg);
  string msg;
  msg.resize(len);
  ifs.read(&msg[0], len);

  string unpacked = bundle::unpack(msg);

  ofstream ofs;
  ofs.open(ofilename, std::ios::binary);
  ofs.write(&unpacked[0], unpacked.size());

  ifs.close();
  ofs.close();
  return 0;
}
